﻿using Finance.ErrorCode;
using Finance.API.Write.Application.Command.FinancialCategoryCommand;
using Finance.Domain;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

namespace Finance.API.Write.Controllers
{
    /// <summary>
    /// 财务类型
    /// </summary>
    //[Authorize]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FinancialCategoryController : ControllerBase
    {
        IMediator mediator;
        ILogger<FinancialCategoryController> logger;

        public FinancialCategoryController(IMediator mediator, ILogger<FinancialCategoryController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 财务类型财务类别添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddFinancialCategoryCommand(AddFinancialCategoryCommand request)
        {
            try
            {
                
               return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("财务类型财务类别添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 财务数据财务类别逻辑删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DelFinancialCategoryCommand(int financialCategoryId )
        {
            try
            {
                DelFinancialCategoryCommand request = new DelFinancialCategoryCommand()
                {
                    financialCategoryId=financialCategoryId
                };
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("财务数据财务类别逻辑删除失败" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 财务数据财务类别修改
        /// </summary>
        /// <param name="financial"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdFinancialCategoryCommand(UpdFinancialCategoryCommand request)
        {
            try
            {
                
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("财务数据财务类别修改失败" + ex.Message);
                throw;
            }
        }








    }
}
